<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      var str1 = "abcddcba";
      var str2 = "你好世界世好你";
      var str3 = "你好世界";
      function huiwen(str) {
        var flag = true;
        for (var i = 0; i < parseInt(str.length); i++) {
          if (str[i] != str[str.length - 1 - i]) {
            flag = false;
            break;
          }
        }
        return flag;
      }

      console.log(huiwen(str1));
      console.log(huiwen(str2));
      console.log(huiwen(str3));
    </script>
  </body>
</html>
